package com.stox.charting.ui.swing.presenter.delegate.builder;

import java.awt.BorderLayout;

import com.stox.charting.ui.swing.model.DefaultAxis;
import com.stox.charting.ui.swing.model.Orientation;
import com.stox.charting.ui.swing.model.indicator.VolumeChart;
import com.stox.charting.ui.swing.model.price.DateAxis;
import com.stox.charting.ui.swing.model.price.InfoAxis;
import com.stox.charting.ui.swing.model.price.PriceChart;
import com.stox.charting.ui.swing.model.price.PriceChartView;
import com.stox.charting.ui.swing.view.ChartView;
import com.stox.charting.ui.swing.view.ChartView.Type;
import com.stox.charting.ui.swing.view.ChartingInternalFrameView;
import com.stox.core.model.IBar;

public class ChartViewBuilder {

	private ChartBuilder chartBuilder;
	private AxisBuilder axisBuilder;
	
	@SuppressWarnings("unchecked")
	public ChartView build(Type type, ChartingInternalFrameView chartingInternalFrameView){
		switch(type){
		case INDICATOR :
			throw new UnsupportedOperationException();
		case PRICE : 
			PriceChartView priceChartView =  new PriceChartView(chartingInternalFrameView);
			PriceChart<? extends IBar> priceChart= (PriceChart<? extends IBar>)chartBuilder.build(PriceChart.class);
			priceChartView.setPriceChart(priceChart);
			VolumeChart volumeChart = chartBuilder.build(VolumeChart.class);
			priceChartView.setVolumeChart(volumeChart);
			
			priceChartView.setPriceAxis(axisBuilder.build(DefaultAxis.class, priceChartView, Orientation.VERTICAL, BorderLayout.WEST, priceChart.getModel()));
			priceChartView.setInfoAxis(axisBuilder.build(InfoAxis.class, priceChartView, Orientation.HORIZONTAL, BorderLayout.NORTH, priceChart.getModel()));
			priceChartView.setDateAxis(axisBuilder.build(DateAxis.class, priceChartView, Orientation.HORIZONTAL, BorderLayout.SOUTH, priceChart.getModel()));
			priceChartView.setVolumeAxis(axisBuilder.build(DefaultAxis.class, priceChartView, Orientation.VERTICAL, BorderLayout.EAST, priceChart.getModel()));
			return priceChartView;
		}
		return null;
	}
	
	public ChartBuilder getChartBuilder() {
		return chartBuilder;
	}

	public void setChartBuilder(ChartBuilder chartBuilder) {
		this.chartBuilder = chartBuilder;
	}

	public AxisBuilder getAxisBuilder() {
		return axisBuilder;
	}

	public void setAxisBuilder(AxisBuilder axisBuilder) {
		this.axisBuilder = axisBuilder;
	}
	
}
